package com.yanqu.road.dao.impl.player;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import org.apache.mina.util.ConcurrentHashSet;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Set;

public class InnerUserBlackDaoImpl extends TempDao {

    public Set<Long> getInnerUserBlacklistMap(long serverId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Set<Long> set = new ConcurrentHashSet<>();
        String sql = "select userId from t_s_inner_user_black where serverId=?";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setLong(1, serverId);
            rs = call.executeQuery();
            while (rs.next()) {
                long userId = rs.getLong("userId");
                set.add(userId);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return set;
    }
}
